//
//  YYMusicViewController.m
//  ONE
//
//  Created by dllo on 16/6/7.
//  Copyright © 2016年 GroupNine. All rights reserved.
//

#import "YYMusicViewController.h"
#import "YYCollectionViewCell.h"
#import "LFBNetTool.h"

@interface YYMusicViewController ()<UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>

/** 底层collectionView */
@property (nonatomic, strong) UICollectionView *collectionView;
@property (nonatomic, strong) UICollectionViewFlowLayout *flowLayout;


@end

@implementation YYMusicViewController

- (void)dealloc
{
    self.collectionView.delegate = nil;
    self.collectionView.dataSource = nil;
    
}

+(UINavigationController *)defaultMusicNavigationController
{
    static UINavigationController *nav = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        YYMusicViewController *musicVC = [[YYMusicViewController alloc] init];
        nav = [[UINavigationController alloc] initWithRootViewController:musicVC];
    });
    return nav;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor redColor];
    /** 底层collectionView */
    [self createCollectionView];
    
    
    self.edgesForExtendedLayout = UIRectEdgeAll;
    self.navigationItem.title = @"音乐";
    
    [self addNavigationBarLeftSearchItem];
    [self addNavigationBarRightMeItem];
}

#pragma mark -- 底层collectionView
- (void)createCollectionView
{
    self.flowLayout = [[UICollectionViewFlowLayout alloc] init];
    self.flowLayout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
    self.flowLayout.minimumLineSpacing = 0;
    self.flowLayout.minimumInteritemSpacing = 0;
    self.flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    self.flowLayout.itemSize = CGSizeMake(SCREEN_WIDTH, SCREEN_HEIGHT);
    
    self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT) collectionViewLayout:_flowLayout];
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    self.collectionView.pagingEnabled = YES;
    [self.view addSubview:_collectionView];
    
    /** 注册cell */
    [self.collectionView registerClass:[YYCollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
    
}

#pragma mark -- collectionView必须实现方法(一)number
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 10;
}

#pragma mark -- collectionView必须实现方法(二) cell 内容
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    YYCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    cell.backgroundColor = [UIColor cyanColor];
    return cell;
}

#pragma mark -- 数据解析
- (void)createDataSource
{
    self.dataSource = [NSMutableArray array];
    [LFBNetTool getNetWithURL:[NSString stringWithFormat:@"http://v3.wufazhuce.com:8000/api/music/detail/432"] Body:nil Header:nil Response:LFBJSON Success:^(id result) {
        NSDictionary *dict = [result objectForKey:@"data"];
        
    } Failure:^(NSError *error) {
        NSLog(@"error: %@", error);
    }];
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
